export function formatTimestampWithWeekday(timestamp:any) {
    const now = new Date();
    const messageDate:any = new Date(timestamp);
    const today:any = new Date(now.getFullYear(), now.getMonth(), now.getDate());
    const yesterday:any = new Date(today - 86400000); // 一天的毫秒数
    const dayBeforeYesterday = new Date(yesterday - 86400000); // 再前一天

    // 判断消息发送的时间
    if (messageDate >= today) {
        return `${formatTime(messageDate)}`;
    } else if (messageDate >= yesterday) {
        return `昨天 ${formatTime(messageDate)}`;
    } else if (messageDate >= dayBeforeYesterday) {
        return `前天 ${formatTime(messageDate)}`;
    } else if (messageDate >= today - 604800000) { // 一周的毫秒数
        return formatFullDateWithWeekday(messageDate);
    } else {
        return formatFullDate(messageDate);
    }
}

function formatTime(date:any) {
    return `${date.getHours()}:${date.getMinutes().toString().padStart(2, '0')}`;
}

function formatFullDateWithWeekday(date:any) {
    const weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
    const weekday = weekdays[date.getDay()];
    return `${weekday} ${formatFullDate(date)}`;
}

function formatFullDate(date:any) {
    return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')} ${formatTime(date)}`;
}